﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ResultsManagementSystem
{
    public partial class AcademicAffairsSecretaryInterface : Form
    {
        public AcademicAffairsSecretaryInterface()
        {
            InitializeComponent();
        }

        private void calculate_Click(object sender, EventArgs e)
        {
            ResultDao resultDao = new ResultDao();

            resultDao.insertResult();

            MessageBox.Show("统计结束！");
        }

        private void queryAll_Click(object sender, EventArgs e)
        {
            ResultDao resultDao = new ResultDao();

            List<Result> resultList = resultDao.queryAllResult();

            this.resultListBox.Items.Clear();

            Result result = new Result();

            for (int i = 0; i < resultList.Count; i++ )
            {
                result = resultList.ElementAt(i);

                resultListBox.Items.Add("学号：" + result.getNumber() + "平均分：" + result.getAve().ToString() + "最高分：" + result.getMax().ToString() + "最低分：" + result.getMin().ToString());
            }
        }

        private void querySingle_Click(object sender, EventArgs e)
        {
            ResultDao resultDao = new ResultDao();

            Result result = resultDao.queryResult(this.numberTextBox.Text);

            this.resultListBox.Items.Clear();

            if(result != null)
            {
                resultListBox.Items.Add("学号：" + result.getNumber() + "平均分：" + result.getAve().ToString() + "最高分：" + result.getMax().ToString() + "最低分：" + result.getMin().ToString());
            }
            else
            {
                MessageBox.Show("没有此同学！");
            }
        }

        private void good_Click(object sender, EventArgs e)
        {
            ResultDao resultDao = new ResultDao();

            List<Result> resultList = resultDao.queryMoreThen85Result();

            this.resultListBox.Items.Clear();

            Result result = new Result();

            for (int i = 0; i < resultList.Count; i++)
            {
                result = resultList.ElementAt(i);

                resultListBox.Items.Add("学号：" + result.getNumber() + "平均分：" + result.getAve().ToString() + "最高分：" + result.getMax().ToString() + "最低分：" + result.getMin().ToString());
            }
        }
    }
}
